from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
from lib.common import AbstractHandler
import logging
app_logger = logging.getLogger("student")
from django.core.cache import cache
from urllib.parse import unquote
from urllib import parse
import json
from lib.douyin import run


class Handler(AbstractHandler):

    def __init__(self):
        AbstractHandler.__init__(self, app_logger)

    @csrf_exempt
    def handle_doudian_notify(self, request):
        app_logger.error("这是抖店的回调通知")
        text = unquote(request.body.decode(), 'utf-8')
        dy_list = json.loads(text)
        app_logger.error(dy_list)
        for v in dy_list:
            data = json.loads(v['data'])
            res = run.getOrder(data['p_id'])
            app_logger.error(res)
        return JsonResponse({"code": 0, "msg": "success"})

doudian_handler = Handler()